﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="img_list.aspx.cs" Inherits="Album_img_list" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <Custom:Header runat="server" />
    <script type="text/javascript" src="../js/ajaxupload.js"></script>
    <style type="text/css">
        .pupbox{width:300px;padding:20px;}
        .pupbox ul li{line-height:30px;}
        .loading2{padding-left:18px;line-height:22px; background-position:left center;display:none;}
    </style>
    <script type="text/javascript">
        $(function() {
            var wbox=$("a:contains(添加)").click(function() {
                return false;
            }).wBox({
                title: "添加图片",
                html: "<div class='pupbox'><ul><li>图片名称：<input name='imgname' /></li><li>选择图片：<input type='file' name='upfile' id='upfile' /></li><li><input type='button' class='btnsave' value='保存' /><span class='loading2'>数据提交中…</span></li></ul></div>",
                show: false,
                callBack: function() {
                    $(".btnsave").click(function() {
                        var parent=$(this).next();
                        if(parent.is(":visible")) return false;
                        
                        var postdata = { myaction: "save_file", imgname: $("input[name=imgname]").val(),aid:"<%=Request["id"] %>",fileid:"upfile" };
                        $(this).hide();
                        parent.show();
                        $.ajaxFileUpload({
                            url: "action.aspx?time=" + Math.random(),
                            type: "POST",
                            secureuri: false,
                            fileElementId: postdata.fileid,
                            data: postdata,
                            dataType: "json",
                            success: function(data) {
                                if (data.succ) {
                                    location="?id=<%=Request["id"] %>";
                                }
                                else {
                                    alert(data.msg);
                                }
                            },
                            error: function(data, status, e) {
                                alert("提交发生意外。")
                                $("body").append(data.responseText)
                            },
                            complete: function() {
                                parent.hide();
                                $(".btnsave").show();
                            }
                        });

                    });
                }
            });

            $("a:contains(删除)").click(function() {
                var ids = "";
                $("input[name=checkboxid]:checked").each(function() {
                    ids += $(this).val() + ","
                });
                if (ids == "") {
                    alert("未选中任何待删除记录");
                } else {
                    $.ajax({
                        url: "action.aspx",
                        dataType: "json",
                        data: { action: "img_del", ids: ids },
                        success: function(data) {
                            if (data.succ) {
                                $("input[name=checkboxid]:checked").each(function() {
                                    $("tr[imgid=" + $(this).val() + "]").remove();
                                });

                            } else {
                                $.each(data.ids,function(val,i){
                                    $("tr[imgid=" + val + "]").remove();
                                });
                                alert(data.msg);
                            }
                        },
                        error: function(req) {
                            alert("提交发生意外。");
                        },
                        beforeSend: function() {

                        },
                        complete: function() {

                        }
                    });
                }
                return false;
            });

        })
    </script>
</head>
<body>
    <form runat="server">
        <Custom:ToolBar ID="ToolBar" runat="server" />
        <table  border="0" class="tabList" align="center" cellpadding="0" cellspacing="1">
        <tr class="tbhead">
            <td width="60" align=center>
                全<input type="checkbox" id="chkall" />选
            </td>
            <td>
               图片名称
            </td>
            <td>相册</td>
            <td>
                图片
            </td>
            <td>操作</td>
        </tr>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <tr imgid="<%#Eval("ID") %>">
                <td>
                    <div align="center">
                        <input name="checkboxid" type="checkbox" value="<%#Eval("ID") %>" />
                    </div>
                </td>
                <td>
                   <%#Eval("imgName")%>
                </td>
                <td><%#Eval("albumid") %></td>
                <td><img src="http://img.ds568.net/album/a<%#Request["id"] %>/<%#Eval("filename") %>" onerror="$(this).hide();" onload="changeImg(this,150,150)" /></td>
                <td>
                    <a href="javascript:window.clipboardData.setData('Text',$(this).parent().prev().find('img').attr('src'));">复制连接</a>
                </td>
            </tr>
            </ItemTemplate>
        </asp:Repeater>
    </table>
   </form>
</body>
</html>
